package com.xlh.wjdcserver.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.common.result.Result;
import com.property.dto.PermissionAddDTO;
import com.property.dto.RoleAddDTO;
import com.property.dto.RoleEditDTO;
import com.property.dto.RolePageDTO;
import com.property.entity.Permission;
import com.property.entity.Role;
import com.property.vo.PermissionVO;
import com.xlh.wjdcserver.service.RoleService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @Operation(summary = "添加角色")
    @PostMapping("/add")
    public Result add(@RequestBody RoleAddDTO roleAddDTO)
    {
        roleService.add(roleAddDTO);
        return Result.ok();
    }

    @Operation(summary = "编辑角色")
    @PutMapping("/edit")
    public Result edit(@RequestBody RoleEditDTO roleEditDTO)
    {
        roleService.edit(roleEditDTO);
        return Result.ok();
    }

    @Operation(summary = "分页查询角色")
    @GetMapping("/page")
    public Result<Page<Role>> rolePage(RolePageDTO rolePageDTO)
    {
        return Result.ok(roleService.rolePage(rolePageDTO));
    }


    @Operation(summary = "给角色添加权限")
    @PostMapping("/addPermission")
    public Result addPermission(@RequestBody PermissionAddDTO permissionAddDTO)
    {
        roleService.addPermission(permissionAddDTO);
        return Result.ok();
    }

    @Operation(summary = "获取角色权限列表")
    @GetMapping("/getPerByRoleId")
    public Result<List<PermissionVO>> getPerByRoleId(@RequestParam String roleId)
    {
        return Result.ok(roleService.getPerByRoleId(roleId));
    }


    @Operation(summary = "获取权限列表")
    @GetMapping("/permissionList")
    public Result<List<Permission>> permissionList()
    {
        return Result.ok(roleService.permissionList());
    }

    @Operation(summary = "获取角色列表")
    @GetMapping("/list")
    public Result<List<Role>> list()
    {
        return Result.ok(roleService.list());
    }



}
